package com.assic.utils.math;

/**
 * 
 * @author AlianGGGG
 * @version 1.0
 */
@Deprecated
public class Matris__ {
	// private static double[][] matrixC ;
	/**
	 * 
	 * 解矩阵方程
	 * 
	 * @param A
	 *            矩阵
	 * @param b
	 *            列阵
	 * @return matrixC 列阵
	 */
	public static double[][] Calcul(double[][] A, double[][] b) {
		double[][] matrixC = new double[A.length][1];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < b[i].length; j++) {
				for (int k = 0; k < b.length; k++)
					matrixC[i][j] += A[i][k] * b[k][j];
			}
		}
		return matrixC;
	}

	/**
	 * 
	 * 矩阵相乘
	 * 
	 * @param A
	 *            矩阵
	 * @param b
	 *            列阵
	 * 
	 * @return c 列阵
	 */
	public static double[][] MatrixMultiply(double[][] A, double[][] b) {

		double[][] c = new double[A.length][1];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A.length; j++) {
				c[i][0] += A[i][j] * b[j][0];
			}
		}
		return c;
	}

	public static void main(String[] args) {
		double[][] a = { { 2, -3, 3 }, { -1, 2, 1 }, { 0.5, 1, 2 } };
		double[][] b = { { 1 }, { 9 }, { 1 } };
		for (double[] ds : Equations.solve(a, b)) {
			System.out.println(ds[0]);
		}
		double x, y, z;
		double a1 = 2, b1 = -3, c1 = 3, d1 = 1, a2 = -1, b2 = 2, c2 = 1, d2 = 9, a3 = 0.5, b3 = 1, c3 = 2, d3 = 11;
		x = ((d1 * c2 - d2 * c1) * (b2 * c3 - b3 * c2) - (d2 * c3 - d3 * c2) * (b1 * c2 - b2 * c1))
				/ ((a1 * c2 - a2 * c1) * (b2 * c3 - b3 * c2) - (a2 * c3 - a3 * c2) * (b1 * c2 - b2 * c1));
		y = ((d1 * c2 - d2 * c1) * (a2 * c3 - a3 * c2) - (d2 * c3 - d3 * c2) * (a1 * c2 - a2 * c1))
				/ ((a2 * c3 - a3 * c2) * (b1 * c2 - b2 * c1) - (a1 * c2 - a2 * c1) * (b2 * c3 - b3 * c2));
		z = (d1 - a1 * x - b1 * y) / c1;
		System.out.println("the formular answer is: x=" + x + " y=" + y + " z=" + z);

	}

}
